package com.youlemall.manager.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.youlemall.common.pojo.PageResult;
import com.youlemall.pojo.ItemCat;
import com.youlemall.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 2 * @Author: kevin
 * 3 * @Date: 2019/7/16 20:00
 * 4
 */
@RestController
@RequestMapping("/itemCat")
public class ItemCatController {

	@Reference
	private ItemCatService itemCatService;

	@GetMapping("/findItemCatByParentId")
	public List<ItemCat> findItemCatByParentId(Long parentId) {
		try {
			return itemCatService.findItemCatByParentId(parentId);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	@PostMapping("/save")
	public Boolean saveItemCat(@RequestBody ItemCat itemCat){
		try {
			itemCatService.save(itemCat);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@PostMapping("/update")
	public Boolean updateItemCat(@RequestBody ItemCat itemCat){
		try {
			itemCatService.update(itemCat);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@GetMapping("/delete")
	public Boolean deleteItemCat(Long[] ids){
		try {
			itemCatService.deleteAll(ids);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

}
